package com.next

class PlayPosition
{
    String name
    String code
    String description

    String status
    // 打位状态

    Contact contact
    // 客户
    User user
    // 球童

    String level

    Date createdDate = new Date()
    Date modifiedDate = new Date()
    User createBy
    User modifyBy

    static constraints = {
        name maxSize: 64
        code unique: true
        description blank: true, nullable: true, type: "text"

        status blank: true, nullable: true
        status inList: ['可选', '不可选']
        level blank: true, nullable: true
        level inList: ['一层', '二层']
        user nullable: true, blank: true
        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true
    }

    def springSecurityService

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        createBy = User.findByUsername(username)

        if (!user)
        {
            user = createBy
        }
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }

    String toString()
    {
        name
    }

    static mapping = {
        sort 'code'
    }
}
